/**
 * 
 */
package org.oos.dao.exceptions;

import static org.oos.util.TextUtils.convertStreamToString;

import java.io.IOException;

import org.oos.util.Log;

import com.google.api.client.http.HttpResponse;

public class CreationException extends Exception {

	private HttpResponse response;
	
	private static final long serialVersionUID = 4633477268675212243L;

	public CreationException() {
	}

	public CreationException(String message) {
		super(message);
	}

	public CreationException(Throwable cause) {
		super(cause);
	}

	public CreationException(String message, Throwable cause) {
		super(message, cause);
	}
	
	public void setResponse(HttpResponse response) {
		this.response = response;
	}
	
	public HttpResponse getResponse() {
		return response;
	}
	
	@Override
	public String getMessage() {
		String result = null;
		try {
			if (getResponse() != null) {
				result = convertStreamToString(getResponse().getContent());
			}
		} catch (IOException e) {
			Log.wtf(e);
			result = e.getMessage();
		}
		if (result == null) {
			result = super.getMessage();
		}
		return result;
	}

}